<include file="Public:header" />
<style>
    .viewEditBox8749{display:none;}
    input,textarea{border:1px solid #ccc; border-radius:2px; box-shadow:0 1px 5px #ccc inset; text-indent:0.5em;}
    input{height:35px; line-height:1;}
    body{background:#f5f5f5;}
    .list-group {
        margin-bottom: 5px;
    }
    .pages {
        text-align: center;
    }
    a{color:#333;}
    .panel{background:#fff;}
    .headernav a{font-size:1.5em; color:#000;}
    .media{padding-left:5px; padding-bottom:10px;}
</style>
<script src="__PUBLIC__/Js/validform/Validform.js"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/validform/style.css">
<script>
    $.holdReady(false);
    $(document).ready(function(e) {
        $.ajax({
            url:"{:U('Ajax/getRegion')}",
            data:"",
            type:"POST",
            dataType:"html",
            success: function(data){
                $('#areabox').html(data);
            }});
    });
    function removnextAll(e){
        if($(e).next().length>0){
            removnextAll($(e).next());
            $(e).next().remove();
        }
    }
    function sendRegion(e){
        if(e.value>0){
            $.ajax({
                url:"{:U('Ajax/getRegion')}",
                data:"fid="+e.value,
                type:"POST",
                dataType:"html",
                success: function(data){
                    removnextAll(e);
                    $(e).parent().append(data);
                }
            });
        }else{
            removnextAll(e);
        }
        return false;
    }
</script>
<body>
<div style="background:#fff; height:40px; line-height:40px; border-bottom:1px solid #ccc;" class="headernav">
    <a href="javascript:history.go(-1);" style="height:40px; width:40px; display:block; float:left; text-align:center;"><i class="fa fa-angle-left"></i></a>
    <a href="__APP__/" style="height:40px; width:40px; display:block; float:right; text-align:center;"><i class="fa fa-home"></i></a>
    <a href="{:U('Cart/index')}" style="height:40px; width:40px; display:block; float:right; text-align:center;"><i class="fa fa-shopping-cart"></i></a>
</div>
<form class="checkoutform" id="checkout" action="<?php echo U('createOrder');?>" method="post">
    <div class="main">
        <!-- 免运费 -->
        <eq name="noshipping" value="0">
            <div class="panel panel-default" style="border-radius:0; margin-bottom:5px; margin-top:5px;">
                <div class="panel-body">
                    <a href="javascript:void(0);" onClick="editAddress();">
                        <div class="row">
                            <div class="col-xs-2"><i class="fa fa-truck" style="font-size:2.5em;"></i></div>
                            <div class="col-xs-8">

            <span style="color:red; font-size:14px;" >
            <empty name="address">
                <span id="getaddress" style="color:#000000; font-size:13px; "><a href="<?php if(!is_weixin()){?><?php echo U('address');?><?php }?>">点击这里填写地址:</a></span>
                <else />
                <span id="getaddress" style="color:#000000; font-size:13px; ">{$yourname}&nbsp;&nbsp;{$tel}&nbsp;&nbsp;{$address}</span>
            </empty>
            </span>
                                <input style="display:none;" name="yourname" datatype="*" type="text" id="yourname" nullmsg="收货人姓名不能为空" error="收货人姓名不能为空" value="{$yourname}">
                                <input style="display:none;" name="address" datatype="*" type="text" id="address" nullmsg="收货地址不能为空" error="收货地址不能为空" value="{$address}">
                                <input style="display:none;" name="tel" datatype="*" type="text" id="tel" nullmsg="电话不能为空" error="电话不能为空" value="{$tel}">
                            </div>
                            <div class="col-xs-2"><i style="font-size:2em; color:#ccc;" class="glyphicon glyphicon-menu-right"></i></div>
                        </div>
                </div></a>

            </div>

            <div style="margin:0 5px;"><a href="{:U('address')}" class="btn btn-success" style="display:block; margin:5px;">手动填写配送地址</a>
            </div>


            <notempty name="addressSign_info">
                <script type="text/javascript">

                    //获取共享地址
                    function editAddress()
                    {
                        WeixinJSBridge.invoke(
                                'editAddress',
                                {$addressSign_info},
                                function(res){
                                    //alert(res.err_msg);

                                    if(res.err_msg == "edit_address:ok"){

                                        var value1 = res.proviceFirstStageName;
                                        var value2 = res.addressCitySecondStageName;
                                        var value3 = res.addressCountiesThirdStageName;
                                        var value4 = res.addressDetailInfo;
                                        var address = value1+value2+value3+value4
                                        var tel = res.telNumber;
                                        var username = res.userName;
                                        //alert(value1 + value2 + value3 + value4 + ":" + tel+":"+username);
                                        var getaddress = "收件人："+username+"&nbsp;电话:&nbsp;"+tel+" <br/> "+"&nbsp;&nbsp;&nbsp;&nbsp;收货地址：&nbsp;"+address;

                                        //alert(username == undefined);
                                        if(username == undefined || tel == undefined || address == NaN){
                                            username = '';
                                            tel = '';
                                            address = '';
                                            getaddress = '点击获取地址';
                                        }

                                        $("#getaddress").html(getaddress);
                                        document.getElementById("yourname").value = username ;
                                        document.getElementById("address").value= address ;
                                        document.getElementById("tel").value= tel ;
                                    }else{
                                        //alert(res.err_msg);
                                        //alert('获取微信地址失败，请手动填写地址');
                                    }
                                }
                        );
                    }

                    window.onload = function(){
                        if (typeof WeixinJSBridge == "undefined"){
                            if( document.addEventListener ){
                                document.addEventListener('WeixinJSBridgeReady', editAddress, false);
                            }else if (document.attachEvent){
                                document.attachEvent('WeixinJSBridgeReady', editAddress);
                                document.attachEvent('onWeixinJSBridgeReady', editAddress);
                            }
                        }else{
                            editAddress();
                        }
                    };

                </script>
            </notempty>


        </eq>
        <!-- 免运费结束 -->


        <eq name="noshipping" value="0">
            <notempty name="ShippingList">
                <input type="hidden" name="shipping_id" class="sendListInput" id="shipping_id" value="" nullmsg="请选择配送方式" datatype="*" errormsg="请选择配送方式">
                <!-- Single button -->
                <div class="btn-group" style="padding:5px 10px; width:100%; background:#fff;<if condition="count($ShippingList) eq 1">display:none;</if>">
                <button type="button" style="width:100%;" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <span id="shippingname">请选择配送方式</span> <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" style="width:100%; min-width:100%;">

                    <volist name="ShippingList" id="vo">

                        <li><a href="javascript:void(0);" onClick="setShipping_id({$vo.id},'{$vo.title}');">{$vo.title}</a></li>

                    </volist>

                </ul>
    </div>
    <!-- <div style="margin:0 auto"><input type="text" value="给卖家留言" /></div> -->
    </notempty>
    </eq>
    <!-- 发票管理 -->
    <notempty name="InvoiceList">
        <input type="hidden" name="invoice_id" class="sendListInput" id="invoice_id" value="">
        <!-- Single button -->
        <div class="btn-group" style="padding:5px 10px; width:100%; background:#fff;">
            <button type="button" style="width:100%;" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <span id="invoicename">选择发票类型</span> <span class="caret"></span>
            </button>
            <ul class="dropdown-menu" style="width:100%; min-width:100%;">
                <li><a href="javascript:void(0);" onClick="setInvoice_id(0,'不需要发票');">不需要发票</a></li>
                <volist name="InvoiceList" id="vo">
                    <li><a href="javascript:void(0);" onClick="setInvoice_id({$vo.id},'{$vo.title}');">{$vo.title}</a></li>
                </volist>
            </ul>
        </div>
        <div class="btn-group" id="taxtitle" style="padding:5px 10px; width:100%; display:none; background:#fff;"><input class="form-control" value="" name="taxtitle" type="text" placeholder="请填写抬头" errormsg="您选择开发票，请填写抬头！" nullmsg="您选择开发票，请填写抬头！"></div>
        <script>
            function setInvoice_id(id, title){
                $('#invoice_id').val(id);
                if(id > 0){
                    $('#taxtitle').find('input').attr('datatype', '*');
                    $('#taxtitle').show();
                    $(".checkoutform").Validform({
                        tiptype:1
                    });
                }else{
                    $('#taxtitle').hide();
                    $('#taxtitle').find('input').removeAttr('datatype');
                    $(".checkoutform").Validform({
                        tiptype:1
                    });
                }
                $.post('{:U('echoShippingFee')}', sendData(), function(data){
                    //$('#Shippingfee').html(data.shipping_fee);
                    $('#invoice_id').val(id);
                    $('#invoicename').html('发票类型：'+title+' ');
                    $('#_total').html(data.total);
                },'json');
            }
        </script>
    </notempty>
    <!-- 发票管理 -->
    <!-- 积分抵现 -->
    <div style="margin:5px 5px;"><if condition="is_array($integral_pay) and $integral gt 0">
        <div class="alert alert-warning" role="alert" style="margin-bottom:5px; padding:5px;">
            <strong>温馨提示:</strong>您有{$integral}积分可用于抵现。当前订单允许使用{$integral_pay.integralsum}积分。
        </div>
        <input onBlur="integralPay(this);" type="number" id="integral" name="integral_pay" class="form-control sendListInput">
        <script>
            function integralPay(e){
                $.post('{:U('echointegralPay')}',sendData(), function(data){
                    if(data.status == 1){
                        $('#_total').html('¥'+data.total);

                    }else{
                        error(data.info);
                    }
                }, 'json');
            }
        </script>
    </if></div>
    <!-- 积分抵现结束 -->
    <div style="margin:0 5px;">
        <input  type="text"  name="Guestbook" class="form-control sendListInput" placeholder="给我留言">
    </div>
    <div class="panel panel-info" style=" margin: 5px 5px 0px 5px ;">
        <div class="panel-heading"><i class="glyphicon glyphicon-list"></i> 货品列表1</div>
        <?php $mykey = 0; foreach($productList as $key => $vo){?>
        <?php if($mykey > 0){?>
        <div class="line_" style="height:1px; margin:0 5px; background:#ddd;"></div>
        <?php }?>
        <div class="media" style="position:relative;" id="cart_<?php echo $vo['id'];?>">
            <div class="media-left">
                <a href="##" style="width:80px; height:80px; display:block;">
                    <img width="80" height="80" class="media-object" src="<?php echo getThumbPath($vo['img_url']);?>" data-holder-rendered="true" style="width: 80px; height: 80px;">
                </a>
            </div>
            <div class="media-body">
                <h4 class="media-heading" style="font-weight:normal; color:#999;"><?php echo $vo['title'];?></h4>
                <p>
                    <?php if(!empty($vo['attrmes'][0])){?>
                    <span style="color:rgba(203,189,190,1.00)">规格:&nbsp;&nbsp;</span>
                    <?php foreach($vo['attrmes'] as $vos){?>
                    <span><?php echo $vos ?>&nbsp;&nbsp;</span>
                    <?php }?>
                    <?php }?></p>
                <div class="row" style="line-height:30px;">
                    <div class="col-xs-12"><span style="color:#f00; font-size:1.2em; font-weight:bold; ">¥<?php echo $vo['price'];?></span>&nbsp;&times;&nbsp;<?php echo $vo['num'];?></div>
                </div>
            </div>
            <!--<a href="javascript:void(0);" style="position:absolute; bottom:5px; font-size:1.5em; right:10px;" onClick="deletecart('<?php echo $cartdata[$key][0];?>',this);"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>-->
        </div>
        <?php $mykey++; }?>
    </div>
    <!-- 配送费用 --><notempty name="ShippingList">
    <div style="margin:10px; text-align:right; margin-right:20px;">
        配送费用：<span style="color:#f00; font-size:1.3em; font-weight:bold; font-family:Arial;" id="Shippingfee">0</span>
    </div>
    <script>
        function setShipping_id(id, title){
            $('#shipping_id').val(id);
            $.post('{:U('echoShippingFee')}', sendData(), function(data){
                $('#Shippingfee').html(data.shipping_fee);

                $('#shippingname').html('配送方式：'+title+' ');
                $('#_total').html(data.total);
            },'json');
        }
    </script>
</notempty>
    <!-- 配送费用结束 -->
    <!-- 发票费用 -->
    <!-- 发票费用结束 -->
    <div style="height:80px;"></div>
    <div style="position:fixed; bottom:0px; width:100%; background:rgba(219,214,214,1.00); z-index:10000; height:50px; line-height:50px;">
        <div class="row">
            <div class="col-sm-7 col-xs-7" style="text-align:left; padding:0; padding-left:8px; line-height:50px;">合计：<span style="font-family:Arial;color:red; font-size:1.5em; font-weight:bold;"><span id="_total">¥<?php echo $total;?></span></span></div>
            <div class="col-xs-5" style="padding:0;"><button id="gotopay" disabled type="submit" class="btn-danger" style="display:block; width:100%; text-align:center; font-size:1.3em;" ><i class="glyphicon glyphicon-credit-card"></i> 立即支付</button></div>
        </div>
    </div>
    </div>
</form>
<style>
    table{margin-top:10px !important;}
    td,th{padding:5px 12px !important;}
    #areabox select{margin:5px;}
</style>
<script type="text/javascript">
    $(function(){
        //$(".registerform").Validform();  //就这一行代码！;
        $('#gotopay').removeAttr("disabled");
        $(".checkoutform").Validform({
            tiptype:1
        });
    })
    function sendData(){
        var sendListInput = new Array();
        $('.sendListInput').each(function(index, element) {
            sendListInput.push('"' +$(this).attr('id') + '":"' + $(this).val() + '"');
        });
        return eval('({' + sendListInput.toString() + '})');
    }
    //如果只有一个配送方式，自动选择
    <notempty name="ShippingList">
            <if condition="count($ShippingList) eq 1">
            setShipping_id({$ShippingList.0.id},'{$ShippingList.0.title}');
    </if>
    </notempty>
</script>
<include file="Public:footer" />
